package person.bing.fbcloud.leetcode;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @author: mengfanbing
 * @date: 2020/9/15 10:30
 */
public class Q46 {
    public static void main(String[] args) {
        int[] nums = {1,2,3};
        List<List<Integer>> ans = permute(nums);
        System.out.println(ans);
    }
    public static List<List<Integer>> permute(int[] nums) {
        int length = nums.length;
        List<List<Integer>> ans = new ArrayList<>();
        List<Integer> numList = new ArrayList<>();
        for (int num:nums){
            numList.add(num);
        }
        util(length,ans,new ArrayList<>(),numList,0);
        return ans;
    }
    public static void util(int length,List<List<Integer>> ans,List<Integer> temp,List<Integer> numList,int index) {
        if (numList.size()==0){
            ans.add(new ArrayList<>(temp));
            return;
        }
        if (index == numList.size()){
            return;
        }
        util(length,ans,temp,numList,index+1);
        Integer value = numList.get(index);
        temp.add(value);
        numList.remove(value);
        util(length,ans,temp,numList,0);
    }
}
